Skip to content

Add user agent to globaluserinfo call#1542

Merged
DHardy-WMF merged 2 commits into
masterfrom
theresnotime/T431808
Jul 10, 2026
Merged

Add user agent to globaluserinfo call#1542
DHardy-WMF merged 2 commits into
masterfrom
theresnotime/T431808

Conversation

@theresnotime

Copy link
Copy Markdown
Contributor

Description

Set a compliant User-Agent header on globaluserinfo API requests

The _get_user_info_request helper in TWLight/users/helpers/editor_data.py issued requests via urllib.request.urlopen() without setting a User-Agent header, so requests went out with Python's default Python-urllib/x.y agent. Wikimedia blocks this generic agent per its User Agent policy, returning HTTP 403 Forbidden.

Add a descriptive TWLIGHT_USER_AGENT constant containing the application name, URL, and contact address (sourced from TWLIGHT_ERROR_MAILTO), and send it via urllib.request.Request on the globaluserinfo query.

Phabricator Ticket

How Has This Been Tested?

  • Verified against the live endpoint from the running container: the globaluserinfo call now returns 200 with real data ({'id': 69468694, 'name': 'TheresNoTime-WMF', 'editcount': 709}) instead of 403 Forbidden, and the full OAuth login / editor-creation path completes without the 500.
  • Ran the existing users test suite (python manage.py test TWLight.users.tests)

Types of changes

What types of changes does your code introduce? Add an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Minor change (fix a typo, add a translation tag, add section to README, etc.)

@DHardy-WMF DHardy-WMF left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for including fallbacks with those env vars as well.

@DHardy-WMF DHardy-WMF merged commit 70579f0 into master Jul 10, 2026
3 of 4 checks passed
@DHardy-WMF DHardy-WMF deleted the theresnotime/T431808 branch July 10, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants